#pragma once

#include <pthread.h>

#define INFO        1
#define DEBUG       2
#define ERROR       3
#define FATAL       4
#define LOG_LEVEL   FATAL

// __buf是为了防止这里替换的时候，与调用地方的万一定义过buf出现冲突导致出bug
#define LOG(level, format, ...) do {\
    if (level < LOG_LEVEL) break;\
    time_t t = time(NULL);\
    struct tm* ltm = localtime(&t);\
    char __buf[32] = { 0 };\
    strftime(__buf, 31, "%H:%M:%S", ltm);\
    fprintf(stdout, "[%p %s %s %d] " format "\n", reinterpret_cast<void*>(pthread_self())\
                                                , __buf, __FILE__, __LINE__, ##__VA_ARGS__);\
} while (0)
#define INFO_LOG(format, ...)    LOG(INFO, format, ##__VA_ARGS__)
#define DEBUG_LOG(format, ...)    LOG(DEBUG, format, ##__VA_ARGS__)
#define ERROR_LOG(format, ...)    LOG(ERROR, format, ##__VA_ARGS__)
#define FATAL_LOG(format, ...)    LOG(FATAL, format, ##__VA_ARGS__)
